Repository navigation
The lexical leg of code search cuts its pool on each row's vote times the path penalty the ranking applies - #1673
Merged
Conversation
…, and cuts the lexical pool on them One test word anywhere in a query turned off the test-path penalty, the fan-in prior, the kind prior and file saturation, and one doc word turned off the prose penalty. In a pasted issue or prompt the word says where the fault showed: the top ten went to tests and docs although the code to change was source. A query asks for tests or docs when it carries the word and fits the lexical leg's 32-lexeme term list; a longer one keeps the priors. The penalties multiplied the fused score, after the lexical leg had taken its 200 rows by raw score, so test and doc rows held the pool and the source rows the ranking prefers were never candidates. The leg cuts its pool on the score times the same path factors and returns the rows in score order. The path classes move to server/code/domain/index/path_class.py as patterns Python and ClickHouse both read, so the ranking and the statement agree on which file is a test or a doc. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…he lexical pool cut remains The rule that read a test or doc word as a mention past 32 lexemes is removed. Its support was a set of issues whose targets are source by construction, and it took the asked-for test file out of the top three for long prompts that ask for tests. The intent rule is main's again; `window.py` is unchanged from main. What stays: the lexical leg cuts its pool on the two path penalties the ranking applies to the query, and the path classes have one definition for Python and SQL. One helper (`_path_factors`) turns the query's words into both factors for the leg and for the ranking. Calibration reads the legs after the cut, so leg agreement and the fused head count the rows the pool holds. The comments and the architecture page that said calibration was unaffected now say that. The unit test file is renamed for what it covers and its fixtures name no other project. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…bration reads the leg's own order The pool was cut on lex_score times the path factor. The ranking multiplies the fused reciprocal-rank score by that factor, not the lexical score, so the cut took almost every test, example and prose row out of the leg: a question whose answer is such a file lost it (35 written controls with no test or doc word: target in the top 10 for 20 on main and 1 with that cut). The leg now keeps the 200 rows with the largest factor / (60 + rank), the row's own term in the fused score, and each row votes with its rank in the whole leg. A row in the pool scores what it would score had the leg returned every row. The scan reads the depth past which no row can be in the pool. The statement also returns the leg's own first 200 rows. Calibration fuses and reads those, so leg agreement, the top similarity and abstention do not depend on the cut. The path factor pair is decided once, in `_gather_legs`, and kept on the search state for the leg and the ranking. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…tors `cut_depth` took the smallest factor and assumed none over 1. It now takes the two factors and bounds the depth by the largest over the smallest, so a factor set above 1 cannot leave a pool row past the scan. Only the lexical leg carries a rank on its rows, so the helper that reads it is `_lexical_ranks` and the vector leg votes by position as before. A leg that returned nothing is fused once. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The search test had a pool row in the vector leg's rows, so the legs agreed whether calibration read the leg's own rows or the pool. The vector rows are now the prose row the cut left out and a row the lexical leg never saw: leg agreement and the top similarity hold only on the leg's own order. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fb57e46. Configure here.
…ath class Merge of origin/main. Two conflicts: - `server/code/app/search/priors.py`: main added `_noise_path` over the two regexes this branch moved to `domain/index/path_class.py`. The branch's side is kept, and the definition leg calls `path_class.is_noise_path`, the same two patterns, so one definition decides which path the ranking demotes, the lexical leg cuts on and the definition leg passes over. - `tests/analyzer/shapes.txt`: both sides added a line at one place. The file equals a regeneration from the builders. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…ut moves confidence Calibration reads the lexical leg's own first rows, not the pool the leg cuts on the path penalties, so `retrieval_confidence` and `abstain` do not depend on the cut. The descriptions of `code_fusion_signals` and `code_search_prose_penalty` still said they did. The sentence is removed from both, and the settings reference, schema and example are regenerated. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The cut ranked the rows it read by `lex_score` alone. The score is a sum of idfs over the query words a chunk holds, so the rows of a one-word or two-word query tie by the thousand, and ClickHouse returns equal rows in no fixed order: the wrapped statement numbered them in the reverse of the order the plain statement returns them in. On a table that holds the source tree before `tests/`, the test rows took the first ranks, and with them the pool and the rows calibration reads. Measured on a 70,000-chunk namespace against main: the query `queryset` matches 1,930 chunks with one score (338 source, 340 prose, 1,252 test). Main returns 200 source rows and the cut returned 200 test rows. Of 18 short queries, the lexical-only top 10 was all test rows for six that are all source on main, and `queryset filter` went from confidence 0.618 to 0.348 and abstained. The scan and the rank now order by the score, then by the factor of the row's path, the largest first. Rows the ranking demotes less rank first among equal scores whatever order the table holds them in, and the scan's depth keeps them. The plain statement is unchanged. The 18 queries return source rows as on main. Two tests on clickhouse-local hold a 600-row tie with the source rows stored between benchmark rows and test rows; one of them fails on the statement before this change. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
9 tasks done
This was referenced Nov 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Related: #1664
Related: #1671
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
code.searchkeeps source rows among its lexical candidates that test and doc rows used to displace: for a query that does not ask for tests or docs, the lexical leg keeps the 200 rows whose reciprocal-rank vote times the ranking's path penalty is largest, each row votes with its rank in the whole leg, and rows with one lexical score rank source first.retrieval_confidenceandabstainare still computed from the leg's first 200 rows; the lexical statement reads more for these queries.Why
The path penalties acted after the pool was cut. The lexical leg returned its first 200 rows by rank. Fusion gives a row
1 / (60 + rank), and the ranking multiplies that by 0.35 on a test, example or benchmark path and bycode_search_prose_penaltyon a prose file. So the leg kept test rows worth0.35 / 260and dropped source rows worth up to1 / 261.Measured on 29 public issues whose fixes change source files only (the measurement is described under Tests):
What the change does:
factor / (60 + rank), the row's own term in the fused score.factoris the pair the ranking applies to the query: 0.35 andcode_search_prose_penalty, each 1 when the query's words turn that penalty off or the fusion signals are off.1 / 400, not with its place among the rows that survived. A row in the pool scores what it would score if the leg returned every row.tests/, test rows took the first ranks, the pool and the rows calibration reads.querysetmatches 1,930 chunks of a 70,000-chunk namespace with one score (338 source, 340 prose, 1,252 test): main returns 200 source rows, the head before this key returned 200 test rows, and this head returns 200 source rows.260 * hi / lo - 60can be in the pool, whereloandhiare the smallest and largest factor a path can get: 2,912 rows for both default penalties, 980 for the prose penalty alone, 683 for the test penalty alone, never more than 10,000.server/code/domain/index/path_class.py, patterns that Python'sreand ClickHouse'smatchboth read) and one decision of the pair (pool_penalties, called once in_gather_legs, kept on the search state for the leg and the ranking).Design calls:
lex_scoretimes the factor. The factor is calibrated for the reciprocal-rank score, and applied to a sum of idfs it removed almost every test and prose row from the leg (83% of the pool to 32%). A set that can contradict it showed the cost: 35 questions whose answer is a test-tree, example or prose file and that carry no test or doc word (under Tests). The asked-for file was in the top 10 for 20 on main and for 1 with that cut. With this head it is 20.What the change does not do:
1 / 260, so they reach the page only with a second vote or a prior. On the 29 issues against main, the changed file reaches the top 3 of the hybrid search and of the hook's request for one more issue (16 to 17, 15 to 16), both in the named half, and the top 5 of the lexical-only search for one more (17 to 18). The hybrid top 10 does not move (18). The lexical-only searches lose one definition at rank 10 (13 to 12 on the issue, 15 to 14 on the first line).retrieval_confidenceof a short query (under Tests). The statement has no key that fixes that order.Scope and risk
server/code/store/index/search.py: the same statement read deeper, inside two window levels),domain/index/pool_cut.py(the constant and the depth),domain/index/path_class.py, a helper instore/index/sql.py, and inserver/code/app/search/:priors.py(pool_penalties;_apply_fusion_signalstakes the pair),gather.py,lexical.py(returns the pool and the leg's first rows),fusion.py(the lexical vote reads the row's rank),pipeline.pyandcalibrate.py(calibration fuses and reads the leg's first rows),rank.py,state.py,track.py(a verdict for a row cut on its path penalty),definitions.py(the definition leg reads the shared path class). The descriptions ofLOOM_CODE_FUSION_SIGNALSandLOOM_CODE_SEARCH_PROSE_PENALTYsay that they also decide the lexical candidates.system.query_log, main to this head, on namespaces of 65,000 to 77,000 chunks and one of 1,769:read_rowsp50 71,633 to 118,075;read_bytesp50 21.4 MiB to 40.5 MiB, p95 31.3 MiB to 51.5 MiB;memory_usagep50 15.3 MiB to 17.1 MiB, p95 46.2 MiB to 47.1 MiB. Ranked by the score alone the wrapped statement took 112 ms at p50 and 26.5 s in sum: the second sort key adds 5%.read_rowsp50 80,780 to 128,839;read_bytesp50 28.8 MiB to 46.5 MiB, p95 31.5 MiB to 51.4 MiB;memory_usagep50 56.8 MiB to 58.2 MiB, p95 92.4 MiB to 92.8 MiB; rows returned 200 to 270 at p50. The leg's wall time p50 308 ms to 406 ms; the request p50 1,071 ms to 1,160 ms.code_search_prose_penaltyreads deeper, up to 10,000 rows (ClickHouse's limit for fetching bodies lazily).testpackage or by a prose page, the asked-for file moves on 4 of 32 requests against main: down one place on 3, and into the top 10 on 1 (under Tests). Source rows the leg now returns pass it. On the head before the tie order, 35 such controls moved on 11 of 105 requests against a build without the cut, each time down, by one to four places.lexical_rankon a unit can exceed 200: it is the row's rank in the whole leg.retrieval_confidence: on 18 queries of one to six words in hybrid mode, confidence differs from main on 17, by 0.001 to 0.200; two rise past 0.4, and one at 0.350 starts abstaining at 0.346. On the 58 issue-text and first-line requests it differs on 3, by 0.001 to 0.003, and none changes whether it abstains.testortestsdirectory.Compatibility, rollout and rollback
lexical_rankcan exceed 200.track_pathhas one more verdict text,beyond pool: lexical <score> over floor <floor>, cut on its path penalty.Tests
Measurement. 29 public issues of two open-source Python web frameworks, each with the commit that fixed it. 14 were named before any measurement (the named half) and 15 were drawn with a fixed seed. Each base commit is indexed whole into its own namespace (64,674 to 76,607 chunks, and one of 1,769), tests and docs included. A request is
POST /v1/code.searchwithtop_k: 10,fresh: trueandlegsas named. "File" is the rank of the first changed file among distinct files; "def" is the rank of the first unit that covers a changed line. The harness and its index are not in the repository. Five runs of the head before the tie order returned identical answers (319 of 319 requests, scores and confidence included), and three rounds of 58 requests on this head did (58 of 58).The vector leg ran on a deterministic n-gram stand-in, not a provider model, so the hybrid rows are the lexical leg plus that stand-in. The lexical-only rows do not depend on it.
This head against main. One harness run each on main
1fd16706d8, which has the definition leg, and on this head, the two servers up together. A cell with one number is the same on both.code.context_pack, first 500 characterscode.context_pack, first lineShort queries, this head against main. 18 queries of one to six words on one 70,000-chunk namespace (
queryset,middleware,queryset filter,model field,how does the paginator count pagesand 13 like them), top 10. A test row is a row under a test, example or benchmark directory.Controls whose answer is not a source file, this head against main. 16 questions on the same namespace, each with its file fixed from the repository listing before any request and none with a test or doc word: 8 answered by a module of the library's
testpackage, 8 by a how-to or topic page. Columns are main and this head.The head before the merge of main and before the tie order (
fb57e46b8f), against the main of that time, which had no definition leg. Everything from here to "Unit tests" was measured on that head, and its control sets were not sent again. The cut on votes it measures is this head's; the tie order it reports beside the cut is the one the second sort key replaces.Three builds: main, the control (that head with both factors forced to 1 in the statement, so the pool is the leg's first 200 rows in the wrapped statement's tie order), and that head. A cell with one number is the same on all three; otherwise it reads main / control / head, and the cut's own effect is control to head.
code.context_pack, first 500 characterscode.context_pack, first linecode.context_packgains and the three first-line lexical definition losses are the tie order, not the cut.Each half of the set:
code.context_pack, first 500 characterscode.context_pack, first lineThe lexical leg's own 200 rows (the leg run in process with and without the factors):
By the factors in force on the issue text:
The deepest row of a pool is at rank 209 to 810 over these 55 statements. The statement returns 271 rows at the median (313 at most): the pool and the rows of the leg's first 200 that are not in it.
Calibration. The hook's request on the 29 issues, as the plugin ships it (an answer is delivered when the search does not abstain and
retrieval_confidenceis at least 0.4). The control and this head are the same in every cell.Controls that can contradict the cut: the answer is not a source file. 21 questions written for this change, each with the files that answer it fixed from the repository listing before any search was sent, and none with a test or doc word: 6 about code under a
testpackage of the library (the test client, the settings override, the live server), 2 about support files of the test tree, 6 answered by a how-to or reference page, 4 by an example application, 2 by a deployment or pattern page, 1 by the test configuration. 14 are sent to a namespace of each half and 7 to the small namespace, which is in the named half: 35 requests, 21 and 14. Columns are main, the earlier head that cut on score times factor, the control, and this head. "Target" is the rank of the first asked-for file among distinct files.testpackage 8 and 8 of 12, prose 7 and 8 of 14, examples 2 and 2 of 4, test support 3 and 2 of 5.Controls that can contradict a length rule. 23 prompts, each with the files it asks for fixed before any run: 14 ask for tests (30 to 40 lexemes), 6 ask for docs, 3 list ten identifiers. Each was sent as a search (
top_k: 10) and in the hook's shape (top_k: 3). Columns are main and this head.Other controls, 46 requests on main, the control and this head:
path_prefix,path_globs)Issues that got worse, control to head. Ranks are file/def,
-for not in the top 10.Control to head, no issue loses a changed file or a changed definition from a page. The tie order alone takes one definition off one (first line, lexical: 3/3 to 4/-).
Latency and cost.
retrieval_work.lexical_leg_ms): median 160 ms to 174 ms, p95 277 ms to 300 ms.system.query_logof those runs: duration p50 118 ms to 174 ms, p95 190 ms to 238 ms;read_rowsp50 72,907 to 122,918;read_bytesp50 25.6 MiB to 42.6 MiB, p95 31.4 MiB to 51.5 MiB;memory_usagep50 42.6 MiB to 56.6 MiB, p95 63.2 MiB to 81.2 MiB; result 696 KiB to 858 KiB.Unit tests.
tests/unit/test_code_lexical_pool_cut.py: the pair of a query, the ranking multiplying by the pair it is handed, the path classes, the factor's SQL, the depth for seven factor pairs, a property test that no row past the depth is in the pool (20 seeds, mixed classes, a factor over 1), a first-ranked test row staying while the last test rows leave, a row voting with its rank in the whole leg, the leg returning the pool and its own first rows, calibration reading the leg's own order while the ranking reads the pool, and whatsearchhands the leg.test_code_lexical_statement.pyholds the plain and the wrapped statement byte for byte.test_code_lexical_token_gate_sql.pyruns the cut on clickhouse-local, including a test row that matches every term and outlasts 130 source rows that match two, which a cut on score times factor drops, and two 600-row ties stored with the source rows between benchmark rows and test rows: the source rows take the first ranks and the pool.test_code_search_provenance.py: thetrack_pathverdict for a row cut on its path penalty.Run here, on this head:
test_code_lexical_token_gate_sql.pycannot create its table on the local clickhouse-local, which lacks the table's vector codec, on main as here. Its 14 bodies pass against the same table without the codec.ruff format --check,ruff check, mypy on the three changed modules, the function-length gate, the settings, docs, SDK and plugin generators with--check, and prettier on the changed Markdown and YAML.On the head before the merge, the test bodies of 50 unit test files were called directly without a pytest session: every body that passes on main passed there.
Left to CI: the full unit suite, the analyzer corpus against a migrated ClickHouse and the integration suite.
AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code. The agent ran the harness on main, the control build and this head, read the per-issue rank changes behind every worse cell, wrote the control questions and fixed their targets before sending them, and ran the gates listed.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make test-unitand applicable integration results are reported by CI; a full local run is not required before pushing.docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code
Note
Medium Risk
Changes core lexical retrieval SQL and fusion semantics for implementation queries; trades higher ClickHouse read depth (hundreds–thousands of rows) for better source recall, with calibration deliberately unchanged.
Overview
code.search no longer takes the lexical leg’s top 200 rows by BM25 alone when test-path and prose penalties apply. The lexical ClickHouse query scans to a bounded depth and keeps the 200 chunks with the largest
path_factor / (60 + lex_rank), while each survivor still fuses using its global leg rank (lex_rank). Calibration, abstention, and leg agreement keep using the leg’s uncut first 200 rows (lexical_head), not the penalty-trimmed pool.Path classification moves into
path_class.pywith patterns shared by Python ranking and SQL (path_penalty_sql).pool_penaltiesdecides the (noise, prose) pair once per query; the lexical leg and post-RRF fusion both use it. Settings/docs now state thatLOOM_CODE_FUSION_SIGNALSandLOOM_CODE_SEARCH_PROSE_PENALTYgovern lexical candidate selection as well as fused-score multipliers.track_pathcan report rows dropped for path penalty despite a strong lexical score.Reviewed by Cursor Bugbot for commit f8408b7. Bugbot is set up for automated code reviews on this repo. Configure here.